﻿<%@ WebHandler Language="C#" Class="RandomCodeHandler" %>

using System;
using System.Web;
using System.Drawing;

public class RandomCodeHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/jpeg";

        using (Bitmap map = new Bitmap(100, 30))
        {
            using (Graphics gr = Graphics.FromImage(map))
            {
                string str = BTS.COMMON.BTSRandomCode.GetRndNumStr();
                HttpCookie cookie = new HttpCookie("randomCode");
                cookie.Value = str;
                cookie.Expires = DateTime.MaxValue;
                context.Response.Cookies.Add(cookie);
                gr.DrawString(str, new Font("Courier New", 20, FontStyle.Italic), Brushes.Blue, new PointF(2, 2));
                map.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}